﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Networking
{
    /// <summary>
    /// Abstract class that represents a packet
    /// </summary>
    public abstract class Packet
    {

        /// <summary>
        /// The type of the packet
        /// </summary>
        public PacketType Type { protected set; get; }

        /// <summary>
        /// Serializes the packet in order to send it
        /// </summary>
        /// <returns>The bytes of the packet</returns>
        public abstract byte[] Serialize();

        /// <summary>
        /// Loads a packet from a byte buffer
        /// </summary>
        /// <param name="buffer"></param>
        public abstract void Load(byte[] buffer);

        /// <summary>
        /// The base constructor should have a PacketType specification
        /// </summary>
        /// <param name="Type">The type of the packet</param>
        public Packet(PacketType Type)
        {
            this.Type = Type;

        }
        /// <summary>
        /// Creates a new instance of Packet extracting all the parameters from the byte buffer
        /// </summary>
        /// <param name="Type">The type of the packet</param>
        /// <param name="buffer">The byte buffer containing all the parameters</param>	
        public Packet(PacketType Type, byte[] buffer)
        {
            this.Type = Type;
            this.Load(buffer);
        }

    }
}